package com.it.zhangjun.protobuf;

import com.google.protobuf.InvalidProtocolBufferException;

/**
 * 功能描述
 *
 * @author z00018123
 * @since 2021-08-23
 */
public class ProtoTest {
    public static void main(String[] args) throws InvalidProtocolBufferException {
        PersonEntity.Person.Builder builder = PersonEntity.Person.newBuilder();
        PersonEntity.Person person = builder.setId(1).setEmail("17751799624@163.com").setName("zhangsan").build();
        System.out.println("before :" + person);
        System.out.println("===========Person Byte==========");
        for (byte b : person.toByteArray()) {
            System.out.print(b);
        }
        System.out.println();
        System.out.println(person.toByteString());
        System.out.println("================================");
        //模拟接收Byte[]，反序列化成Person类
        byte[] byteArray = person.toByteArray();
        PersonEntity.Person person2 = PersonEntity.Person.parseFrom(byteArray);
        System.out.println("after :" + person2.toString());
    }
}
